use "$hssc_robust_IV_estimation.dta", clear

global wf        m_age m_eduyr m_goodhlth m_pens m_ins
global hb        f_age f_eduyr f_goodhlth f_pens f_ins  
global household pid_c1_gender landrentout transinc hhnetasst

*Table 6 
*Estimation results from 2SLS models
***********************************************************************************************
***********************************************************************************************
ivreghdfe numchldtot    $wf $hb $household                                       (treat_it = discty_km nofefmpert) , absorb(year pid_a_m) vce(robust) first keepsingletons
outreg2  using table1,replace  word excel  dec(3) alpha(0.01, 0.05, 0.1) drop($covar) addtext(Year FE, Yes, Individual FE, Yes)   addstat(KP F-Stat, e(widstat),p value of Hansen J-stat, e(jp))  
ivreghdfe cagtest_cn    $wf $hb $household i.educag numchldtot_nonzero ratboy_hh (treat_it = discty_km nofefmpert), absorb(year pid_a_m) vce(robust)  first keepsingletons
outreg2  using table1,append  word excel  dec(3) alpha(0.01, 0.05, 0.1) drop($covar) addtext(Year FE, Yes, Individual FE, Yes)   addstat(KP F-Stat, e(widstat),p value of Hansen J-stat, e(jp))  
ivreghdfe cagtest_math  $wf $hb $household i.educag numchldtot_nonzero ratboy_hh (treat_it = discty_km nofefmpert), absorb(year pid_a_m) vce(robust)  first keepsingletons
outreg2  using table1,append  word excel  dec(3) alpha(0.01, 0.05, 0.1) drop($covar) addtext(Year FE, Yes, Individual FE, Yes)   addstat(KP F-Stat, e(widstat),p value of Hansen J-stat, e(jp))  

*Table A2 
*Estimation results for the first-stage regression of 2SLS models
***********************************************************************************************
***********************************************************************************************
eststo:ivreghdfe numchldtot     $wf $hb $household (treat_it = discty_km nofefmpert), absorb(year pid_a_m) vce(robust) savefirst keepsingletons
est sto first
est restore _ivreg2_treat_it
outreg2   using table1,replace word excel  dec(3) alpha(0.01, 0.05, 0.1) drop($covar) addtext(Year FE, Yes, Individual FE, Yes)   sortvar(treat_it discty_km nofefmpert)
eststo:ivreghdfe cagtest_cn     $wf $hb $household i.educag numchldtot_nonzero ratboy_hh (treat_it = discty_km nofefmpert), absorb(year pid_a_m) vce(robust) savefirst keepsingletons
est sto first
est restore _ivreg2_treat_it
outreg2   using table1,append word excel  dec(3) alpha(0.01, 0.05, 0.1) drop($covar) addtext(Year FE, Yes, Individual FE, Yes)   sortvar(treat_it discty_km nofefmpert)
eststo:ivreghdfe cagtest_math   $wf $hb $household i.educag numchldtot_nonzero ratboy_hh (treat_it = discty_km nofefmpert), absorb(year pid_a_m) vce(robust) savefirst keepsingletons
est sto first
est restore _ivreg2_treat_it
outreg2   using table1,append word excel  dec(3) alpha(0.01, 0.05, 0.1) drop($covar) addtext(Year FE, Yes, Individual FE, Yes)   sortvar(treat_it discty_km nofefmpert)

*Table A3 
*A balance test for instruments
***********************************************************************************************
***********************************************************************************************
duplicates drop cid year,force
global village villhead_age villhead_gender villhead_deuyr lnvillperinc villhlthfc villoldser villkinder villprmschl villtap villclean
reghdfe discty_km      $village , a(cid year) vce(robust) keepsingletons
est store model_1
reghdfe nofefmpert     $village , a(cid year) vce(robust) keepsingletons
est store model_2
outreg2 [model_*] using table1,replace  word excel  dec(3) alpha(0.01, 0.05, 0.1)  addtext(Year FE, Yes, Village FE, Yes)  





